package com.lc.afbx.conn;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/6/6.
 */
@HttpInlet(Conn.INLET_API_INTEGRAL_INTEGRAL)
public class GetApiBaoXianJiFen extends BaseAsyGet<GetApiBaoXianJiFen.Info> {
    public String uid;

    public GetApiBaoXianJiFen(AsyCallBack<GetApiBaoXianJiFen.Info> asyCallBack) {
        super(asyCallBack);
    }

    protected Info parser(JSONObject jsonObject) {

        TOAST = jsonObject.optString("message");

        if (jsonObject.optInt("code") == 200) {

            Info info = new Info();

            JSONObject o = jsonObject.optJSONObject("data");

            Data d = new Data();
            d.integral = o.optString("integral");

            JSONArray array = o.optJSONArray("integral_detail");

            for (int i = 0; i < array.length(); i++) {

                JSONObject o1 =  array.optJSONObject(i);
                Detail detail = new Detail();
                detail.id = o1.optString("id");
                detail.uid = o1.optString("uid");
                detail.insurance_type = o1.optString("insurance_type");
                detail.integral = o1.optString("integral");
                detail.posttime = o1.optString("posttime");
                detail.indate = o1.optString("indate");

                d.detailList.add(detail);
            }

            info.data = d;
            return info;
        }

        return null;
    }


    public static class Info {

        public String code,message;
        public Data data;
    }

    public static class Data {

        public String integral;
        public List<Detail> detailList = new ArrayList();
    }

    public class Detail {
//        "id": "3",
//                "uid": "1",
//                "insurance_type": "购买车险送积分",
//                "integral": "3000",
//                "posttime": "2016-05-10 14:50:32",
//                "indate": "2016-05-10 15:04:56"

        public String id, uid, insurance_type, integral, posttime, indate;
    }
}
